﻿Imports VendasBLL
Imports System.Net
Imports System.Text
Class LoginForm1
    Dim objlogin As New UsuarioBLL
    Public servidor As String
#Region "Login"
    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Try
            If (UsernameTextBox.Text.Trim = "") Then
                Throw New Exception("Campo login obrigatório")
            Else
                Select Case objlogin.login(UsernameTextBox.Text, PasswordTextBox.Text)
                    Case "OK"

                        frmPrincipal.objusuario = objlogin
                        Me.Hide()
                        frmPrincipal.desetivar()
                        frmPrincipal.ShowDialog()
                        Me.Show()
                        UsernameTextBox.Clear()
                        PasswordTextBox.Clear()
                        UsernameTextBox.Focus()
                    Case "Primeiro Login"
                        'PRIMEIRA SENHA... ABRE O FORM PRA ATUALIZAR A SENHA
                        Dim objfrm As New AlterarSenhaCAD
                        objfrm.objlogin = objlogin
                        objfrm.ShowDialog()

                End Select
            End If
        Catch ex As Exception
            If (ex.Message.Contains("Senha inválida")) Then
                PasswordTextBox.Clear()
                PasswordTextBox.Focus()
            End If
            If (ex.Message.Contains("Usuário inválido")) Then
                UsernameTextBox.Clear()
                PasswordTextBox.Clear()
                UsernameTextBox.Focus()
            End If

            MessageBox.Show(ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
    End Sub
#End Region

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

    Private Sub PasswordTextBox_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles UsernameTextBox.KeyPress, PasswordTextBox.KeyPress
        If (Asc(e.KeyChar.ToString) = 32) Then e.Handled = True
    End Sub

    Private Sub LoginForm1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    End Sub
    Sub obter()
        Dim wb As New WebClient
        Dim utf As New UTF8Encoding
        Dim st As String = utf.GetString(wb.DownloadData("http://meuip.datahouse.com.br/")).ToString
        MsgBox(st.Substring(st.IndexOf("</title>") - 14, 14))

    End Sub
End Class
